package main

import (
	"encoding/xml"
	"fmt"
	"io/ioutil"
	"os"
)

type SysInfo struct {
	Type       string             `xml:"type,attr"`
	BIOS       *SysInfoBIOS       `xml:"bios"`
	System     *SysInfoSystem     `xml:"system"`
	BaseBoard  []SysInfoBaseBoard `xml:"baseBoard"`
	Chassis    *SysInfoChassis    `xml:"chassis"`
	Processor  []SysInfoProcessor `xml:"processor"`
	Memory     []SysInfoMemory    `xml:"memory_device"`
	OEMStrings *SysInfoOEMStrings `xml:"oemStrings"`
}

type SysInfoBIOS struct {
	Entry []SysInfoEntry `xml:"entry"`
}

type SysInfoSystem struct {
	Entry []SysInfoEntry `xml:"entry"`
}

type SysInfoBaseBoard struct {
	Entry []SysInfoEntry `xml:"entry"`
}

type SysInfoChassis struct {
	Entry []SysInfoEntry `xml:"entry"`
}

type SysInfoProcessor struct {
	Entry []SysInfoEntry `xml:"entry"`
}

type SysInfoMemory struct {
	Entry []SysInfoEntry `xml:"entry"`
}

type SysInfoOEMStrings struct {
	Entry []string `xml:"entry"`
}

type SysInfoEntry struct {
	Name  string `xml:"name,attr"`
	Value string `xml:",chardata"`
}

func main() {

	xmlFile, err := os.Open("sysinfo_all.xml")
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println("Successfully Opened sysinfo.xml")
	defer xmlFile.Close()

	byteValue, _ := ioutil.ReadAll(xmlFile)

	var si SysInfo
	xml.Unmarshal(byteValue, &si)

	fmt.Printf("sysinfo is: \n%v\n", si)

	fmt.Printf("BIOS info: \n%v\n\n", si.BIOS)
	fmt.Printf("System info: \n%v\n\n", si.System)
	fmt.Printf("BaseBoard info: \n%v\n\n", si.BaseBoard)
	fmt.Printf("Chassis info: \n%v\n\n", si.Chassis)
	fmt.Printf("Processor info: \n%v\n\n", si.Processor)

	for _, value := range si.Memory {
		// fmt.Println("memory:", value.Entry)
		for _, item := range value.Entry {
			fmt.Println(item.Name, item.Value)
		}
	}
}
